﻿@{
    ViewData["Title"] = "登录";
}

<div class="box-login-content">
    <div class="box-title-Login font_bold">登录</div>
    <form class="layui-form">
        <div class="demo-login-container">
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-username"></i>
                    </div>
                    <input type="text" name="username" value="" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs8">
                        <div class="layui-input-wrap">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-vercode"></i>
                            </div>
                            <input type="text" name="vercode" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                    <div class="layui-col-xs4">
                        <div class="box_lofo_vercode">
                            <img style="cursor:pointer;" src='@Url.Action("GetVerifyCode", "Account")' id="CaptchaCodeImg" />
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登录</button>
            </div>
        </div>
    </form>
</div>

@section Scripts {
    <script>
        $(".box-bottom").css("visibility","hidden"); //隐藏导航栏
        $(".box").addClass("frosted"); //添加背景图

        layui.use(['form','layer'], function(){
            var form = layui.form;
            var layer = layui.layer;

            // 提交事件
            form.on('submit(demo-login)', function(data){

                $.post('/Account/Login', data.field, function(res){

                    if(res.code ==200){
                        layer.msg(res.msg);
                        setTimeout(() => {
                            window.location.href = 'https://localhost:44312' //1.5秒后返回首页
                        }, 1500);
                    }
                    else{
                        layer.msg(res.msg);
                    }
                })
                return false; // 阻止默认 form 跳转
            });
        });

        //点击刷新验证码
        $(document).on('click', '#CaptchaCodeImg', function(){
            var d = new Date();
            $("#CaptchaCodeImg").attr("src", "/Login/GetVerifyCode?" + d.getTime());
        })
    </script>
}


